<template>
  <div class="managerApplyWrapper">
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="name" label="姓名" align="center"></el-table-column>
      <el-table-column prop="phone" label="手机号" align="center"></el-table-column>
      <el-table-column prop="address" label="所在地区" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="community" label="所在小区" align="center"></el-table-column>
      <el-table-column prop="households" label="小区户数" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="small" @click="handleView(scope.$index, scope.row)">查看</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)" v-if="scope.row.status==0">删除</el-button>
          <el-button size="small" type="primary" @click="handleCreate(scope.$index, scope.row)" v-if="scope.row.status==0">审核创建</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <el-pagination
      background
      layout="prev, pager, next"
      :total="totalCount" :page-size="paramObj.limit" @current-change="handleCurrentChange">
    </el-pagination>
    
  </div>

</template>

<script>
import api from "@/api/managerApply";

const SUCCESS = 0;
const LIMIT = 10;
export default {
  data() {
    return {
      tableData: [],
      totalCount: 0,
      optId: "",
      paramObj: {
        currentPage: 1,
        limit: LIMIT
      }
    };
  },
  created() {
    this._getData();
  },
  methods: {
    handleView(index, row) {
      this.$router.push({
        path: "/managerApply/detail",
        query: { id: row.id }
      });
    },
    handleCreate(index, row) {
      this.$router.push({
        path: "/manager/edit",
        query: { managerApplyId: row.id }
      });
    },
    handleCurrentChange(val) {
      this.paramObj.currentPage = val;
      this._getData();
    },
    _getData() {
      api.getList(this.paramObj).then(response => {
        if (response.code == SUCCESS) {
          this.tableData = response.data.managerApplyList;
          this.totalCount = response.data.totalCount;
        }
      });
    },
    handleDelete(index, row) {
      this.optId = row.id;

      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this._sureDelete();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    _sureDelete() {
      api.delete(this.optId).then(response => {
        if (response.code == SUCCESS) {
          this._getData();
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        }
      });
    }
  }
};
</script>
